package com.zjx.aop;

import com.zjx.Service.StudentService2;
import com.zjx.entity.Student;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class LogAspect {

	@Autowired
	StudentService2 studentService2;
	public LogAspect(){

		System.out.println("LogAspect...");
	}
    @Pointcut("execution(* com.zjx.Service.StudentService.save(..))")
	private void pt1(){}

//	@Around("pt1()")
//	public void logAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//		String name = proceedingJoinPoint.getSignature().getName();
//
//
//		System.out.println("环绕通知之前==>"+name+"....【args: "+ Arrays.asList(proceedingJoinPoint.getArgs()) +"】");
//		proceedingJoinPoint.proceed();
//		System.out.println("环绕通知之后==>"+name+"....【args: "+ Arrays.asList(proceedingJoinPoint.getArgs()) +"】");
//	}
//	@Before("pt1()")
//	public void logStart(JoinPoint joinPoint){
//		String name = joinPoint.getSignature().getName();
//		System.out.println("前置通知==>"+name+"....【args: "+ Arrays.asList(joinPoint.getArgs()) +"】");
//	}
//
//	@AfterReturning(value = "execution(* com.zjx.aop.HelloService.sayHello(..))",returning = "result")
//	public void logReturn(JoinPoint joinPoint,Object result){
//		String name = joinPoint.getSignature().getName();
//		System.out.println("正常返回==>"+name+"....【args: "+ Arrays.asList(joinPoint.getArgs()) +"】【result: "+result+"】");
//	}

	@After("pt1()")
	public void logEnd(JoinPoint joinPoint) throws Exception {
		Student student = new Student();
		student.setId(7);
		studentService2.delete(student);
	}

//	@AfterThrowing(value = "execution(* com.zjx.aop.HelloService.sayHello(..))",throwing = "e")
//	public void logError(JoinPoint joinPoint,Exception e){
//		String name = joinPoint.getSignature().getName();
//		System.out.println("异常通知==>"+name+"....【args: "+ Arrays.asList(joinPoint.getArgs()) +"】【exception: "+e+"】");
//	}
}
